package com.rfid.a252robot.admin;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DividerItemDecoration;

import com.rfid.a252robot.R;
import com.rfid.a252robot.admin.adapter.UsbDeviceAdapter;
import com.rfid.a252robot.base.BaseListActivity;
import com.rfid.a252robot.base.BasePresenter;
import com.rfid.a252robot.config.GlobalConfig;
import com.rfid.common.log.LogUtils;
import com.spectre.generate.ConfigManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

public class UsbDeviceSelectActivity extends BaseListActivity<UsbDeviceAdapter, UsbDevice, BasePresenter> {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
        System.out.println("usbManager.getDeviceList() size = " +usbManager.getDeviceList().size());
        for (final UsbDevice device : usbManager.getDeviceList().values()) {
            mData.add(device);
        }
        mAdapter.notifyDataSetChanged();
    }

    @Override
    protected int getCountDownTime() {
        return 0;
    }

    @Override
    protected void setSystemUIVisible(boolean show) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_usb_device_select;
    }

    @Override
    protected UsbDeviceAdapter getAdapter() {
        return new UsbDeviceAdapter(mData);
    }

    @Override
    protected int getRecyclerViewId() {
        return R.id.recyclerView;
    }

    @Override
    public BasePresenter getPresenter() {
        return new BasePresenter();
    }

    @Override
    public void onClick(UsbDevice device) {
        System.out.println(device);
        String pid = Integer.toHexString(device.getProductId());
        String vid = Integer.toHexString(device.getVendorId());
        Intent intent = new Intent();
        intent.putExtra("pid",pid);
        intent.putExtra("vid",vid);
        intent.putExtra("serialNumber",device.getSerialNumber());
        setResult(100,intent);
        finish();
    }
}
